package com.lagou.homework.controller;

import com.lagou.homework.dao.CreateCodeDao;
import com.lagou.homework.dao.ValidateCodeDao;
import com.lagou.homework.pojo.AuthCode;
import com.lagou.homework.service.CreateCodeService;
import com.lagou.homework.service.EmailService;
import com.lagou.homework.service.ValidateCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;

@RestController
@RequestMapping("/api/code")
public class CodeController {
    @Autowired
    ValidateCodeService validateCodeService;
    @Autowired
    CreateCodeService createCodeService;

    /*
        生成验证码并发送到邮箱
     */
    @PostMapping("/create/{email}")
    public boolean create(@PathVariable("email") String email){
        return createCodeService.create(email);
    }

    /*
        校验验证码是否正确
     */
    @PostMapping("/validate/{email}/{code}")
    public int validate(@PathVariable("email") String email,@PathVariable("code") String code){
        return validateCodeService.validate(email, code);
    }

}
